﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using DAL;
using Common;


public partial class Customer_Notice : System.Web.UI.Page
{
    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        OneDate.Attributes.Add("onclick","selectDate(this)");
        TwoDate.Attributes.Add("onclick", "selectDate(this)");
        NoticeDataBind();

    }

    private void NoticeDataBind()
    {
        if (MenuType == "452")  //发送
        {
            NoticeOBJ.SelectMethod = "SelectSendNotice";
            NoticeOBJ.SelectCountMethod = "SelectSendNoticeCount";
        }
        if (MenuType == "453") //接收
        {
            NoticeOBJ.SelectMethod = "SelectReceiveNotice";
            NoticeOBJ.SelectCountMethod = "SelectReceiveNoticeCount";
        }

        lv_Notice.DataSourceID = NoticeOBJ.ID;
        lv_Notice.DataBind();

        if (lv_Notice.Items.Count == 0)
            lv_Notice.Visible = false;
    }

    //搜索
    protected void submit_Click(object sender, EventArgs e)
    {
        NoticeDataBind();
    }


   
    //DropDownList分页选择
    protected void PageList_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList pagelist = (DropDownList)sender;

        int CurPage = Convert.ToInt32(pagelist.SelectedValue);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);

        DataPager1.SetPageProperties((CurPage - 1) * DataPager1.PageSize, DataPager1.PageSize, true);
    }

    protected void lv_Message_DataBound(object sender, EventArgs e)
    {
        DropDownList pagelist = (DropDownList)DataPager1.Controls[4].FindControl("PageList");

        int CurPage = WebUtility.GetCurrentPage(DataPager1.StartRowIndex, DataPager1.PageSize);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);
        for (int i = 1; i <= TotalPage; i++)
            pagelist.Items.Add(new ListItem("第" + i.ToString() + "页", i.ToString()));
        pagelist.SelectedValue = CurPage.ToString();
    }

    //删除参数处理
    protected void NoticeOBJ_Deleting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        IDictionary paramsFromPage = e.InputParameters;

        int NoticeKey = 0;
        IDictionaryEnumerator  vs  = paramsFromPage.GetEnumerator();
        while (vs.MoveNext())
        {
            if (vs.Key.ToString() == "")
            {
                NoticeKey = (int)vs.Value;
            }
        }

        paramsFromPage.Clear();
        paramsFromPage.Add("NoticeKey", NoticeKey);
    }
}
